package nio.bytebuffer;


import nio.NioUtils;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * ScatteringReadsTest
 *
 * @author chenxin
 * @date 2022/05/24 15:53
 **/
public class ScatteringReadsTest {

    public static void main(String[] args) throws IOException {

        FileChannel channel = new RandomAccessFile("src/main/resources/words.txt", "r").getChannel();

        ByteBuffer buffer = ByteBuffer.allocate(3);
        ByteBuffer buffer1 = ByteBuffer.allocate(3);
        ByteBuffer buffer2 = ByteBuffer.allocate(5);

        channel.read(new ByteBuffer[]{buffer,buffer1,buffer2});

        buffer.flip();
        buffer1.flip();
        buffer2.flip();

        System.out.println(NioUtils.getStringNotMove(buffer));
        System.out.println(NioUtils.getStringNotMove(buffer1));
        System.out.println(NioUtils.getStringNotMove(buffer2));

    }


}